package com.nemodynamic.cattivial.beansElement;

import java.util.Timer;
import java.util.TimerTask;

import com.nemodynamic.cattivial.utils.DLog;

public class CattivialFoodItem {
	private static final String TAG = "CattivialFoodItem";
	private boolean isEaten;
	private boolean isConsumed;
	private boolean isToBeDrawn;
	private int resourceDrawable;
	private int score;
	private int validityTime;
	private int x;
	private int y;
	private int width;
	private int height;

	private Timer timer;
	private TimerTask timerTask;

	public CattivialFoodItem(int resourceDrawable, int score,
			int validityTimeSecond, int x, int y, int width, int height) {
		isEaten = false;
		isToBeDrawn = false;
		this.resourceDrawable = resourceDrawable;
		this.score = score;
		this.validityTime = validityTimeSecond;
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		timer = new Timer();
		timerTask = new TimerTask() {

			@Override
			public void run() {
				validityTime--;
				if (validityTime == 0) {
					timerTask.cancel();
					isToBeDrawn = false;
					isConsumed = true;
				}
			}
		};
	}

	public boolean isEaten() {
		return isEaten;
	}

	public void setEaten(boolean isEaten) {
		DLog.d(TAG, "Eaten");
		this.isEaten = isEaten;
	}

	public boolean isToBeDrawn() {
		return isToBeDrawn;
	}

	public void setToBeDrawn(boolean isToBeDrawn) {
		this.isToBeDrawn = isToBeDrawn;
	}

	public boolean isConsumed() {
		return isConsumed;
	}

	public void setConsumed(boolean isConsumed) {
		this.isConsumed = isConsumed;
	}

	public int getResourceDrawable() {
		return resourceDrawable;
	}

	public void setResourceDrawable(int resourceDrawable) {
		this.resourceDrawable = resourceDrawable;
	}

	public int getScore() {
		return score;
	}

	public void setScore(int score) {
		this.score = score;
	}

	public int getValidityTime() {
		return validityTime;
	}

	public void setValidityTime(int validityTime) {
		this.validityTime = validityTime;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public void startTimer() {
		timer.scheduleAtFixedRate(timerTask, 1, 1000);
	}

	public void stopTimer() {
		DLog.i(TAG, "Food Timer cancelled");
		timerTask.cancel();
		timer.cancel();
	}

	
}
